/*
 * File:   ipc_controller.h
 * Author: dolphinigle
 *
 * Created on December 2, 2011, 4:13 PM
 */

#ifndef IPC_CONTROLLER_H
#define	IPC_CONTROLLER_H

#include <string>
using std::string;

#include <sys/ipc.h>
#include <sys/types.h>
#include <sys/msg.h>

#include "ipc_controller_interface.h"
#include "ipc_manager.h"

/**
 * Sends command to file system through IPC.
 */
class IPCController : public IPCControllerInterface {
public:
  IPCController(int to_receiver_msq_key, int from_receiver_msq_key);
  virtual ~IPCController() {
    delete manager_;
    msgctl(to_receiver_msq_id_, IPC_RMID, NULL);
    msgctl(from_receiver_msq_id_, IPC_RMID, NULL);
  }

  virtual bool IsExist(const string& path);
  virtual string Ls(const string& path);
  virtual string Mkdir(const string& path);
  virtual string Rm(const string& path);
  virtual string Cp1(const string& path, const string& real_path);
  virtual string Cp2(const string& real_path, const string& path);
  virtual string Cat(const string& path);
  virtual string Close();
  virtual string Status();

private:
  IPCManager* manager_;
  int to_receiver_msq_id_, from_receiver_msq_id_;

  IPCController(const IPCController& orig) {
  }

  bool operator=(const IPCController& orig) {
  }
};

#endif	/* IPC_CONTROLLER_H */

